package com.gaohe.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    //metaObject  tag
    @Override
    public void insertFill(MetaObject metaObject) {
        //如何获取登录人的信息
        String username = BaseContext.getUsername();
        //新增填充逻辑
        metaObject.setValue("createBy",username);
        metaObject.setValue("updateBy",username);
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("updateTime", LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        String username = BaseContext.getUsername();
        metaObject.setValue("updateBy",username);
        metaObject.setValue("updateTime", LocalDateTime.now());
    }
}
